Skip to content

Propagate buy_signal into backtest records and trade analysis - #1

Open
yafeng2003 wants to merge 1 commit into
mainfrom
codex/analyze-current-trading-strategy
Open

Propagate buy_signal into backtest records and trade analysis#1
yafeng2003 wants to merge 1 commit into
mainfrom
codex/analyze-current-trading-strategy

Conversation

@yafeng2003

Copy link
Copy Markdown
Owner

Motivation

  • Make it possible to attribute trades and P/L to originating signals by recording the buy signal throughout the backtest lifecycle.
  • Enable per-signal breakdowns in the trade analysis CSV and console report for deeper quantitative decomposition of strategy behavior.

Description

  • Added an optional buy_signal parameter to BacktestStrategy.upgrade_records and store buy_signal in each record written to self.records via the buy_signal field.
  • When pending orders are filled, pass the originating buy_signal into upgrade_records, and propagate the stored buy_signal for HOLD and SELL records by extracting it from self.holdings where appropriate.
  • In BacktestResultCalculator.analyze_transactions, capture buy_signal from BUY rows into active_positions and include buy_signal in each trade entry produced by _add_trade_record so the analysis CSV contains signal attribution.

Testing

  • No automated tests were executed for this change (analysis-only change).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant